package huas.ant.controller;

import huas.ant.common.PageResult;
import huas.ant.common.Result;
import huas.ant.entity.Coach;
import huas.ant.service.CoachService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admin/coach")
@Slf4j
public class CoachController {
    @Autowired
    private CoachService coachService;
    /**
     * 分页列表查询
     */
    @GetMapping("/page")
    public Result<PageResult> page(@RequestParam(defaultValue = "1") Integer page,
                                   @RequestParam(defaultValue = "10")Integer pageSize){
        log.info("传递的分页参数为：{},{}",page,pageSize);
        PageResult pageResult = coachService.page(page,pageSize);
        return Result.success(pageResult);
    }
    /**
     * 添加教练
     */
    @PostMapping
    public Result insert(@RequestBody Coach coach){
        log.info("添加的设备信息为：{}",coach);
        coachService.insert(coach);
        return Result.success();
    }

    /**
     * 根据教练ID查询设备信息
     */
    @GetMapping("/{id}")
    public Result<Coach> findById(@PathVariable Integer id){
        log.info("要查询的设备id为：{}",id);
        Coach coach = coachService.findById(id);
        return Result.success(coach);
    }
    /**
     * 修改教练信息
     */
    @PutMapping
    public Result update(@RequestBody Coach coach){
        log.info("要修改的设备信息为：{}",coach);
        coachService.update(coach);
        return Result.success();
    }
    /**
     * 删除教练信息
     */
    @DeleteMapping("/{id}")
    public Result delete(@PathVariable Integer id){
        log.info("要删除的设备id为：{}",id);
        coachService.delete(id);
        return Result.success();
    }
}
